$(document).ready(function () {
    var windowHeight = $(window).height()
    $(window).bind('scroll', function () {
        // 滚动条滚动的高度 
        var scrollBarHeight = $(this).scrollTop();
        if ($(window).scrollTop() > 80) {
            $('.section-header').css({
                "box-shadow": "0px 0px 16px 0px rgba(182, 182, 182, 0.5)",
                "background-color": "#fff"
            });
            $(".section-header .logo").css({
                // "background-image": "url(../img/pc/logo.png)"
                "background-image": "url(http://pb0ug959r.bkt.clouddn.com/logo.png)"
            });
            $(".logo-text").css("color", "#808080");
            $(".header-text").css("color", "#808080");
        } else {
            // var navrealHeight1 = 80 - scrollBarHeight;             
            $('.section-header').css({
                "box-shadow": "none",
                "background-color": "transparent"
            });
            $(".section-header .logo").css({
                // "background-image": "url(../img/pc/logo_white.png)"
                "background-image": "url(http://pb0ug959r.bkt.clouddn.com/logo_white.png)"
            });
            $(".logo-text").css("color", "#fff");
            $(".header-text").css("color", "#fff");
        }
        if ($(window).scrollTop() > windowHeight - 300) {
            $(".quotation-box").css("transform", "translateY(475px)");
            $(".quotation-box").css("-ms-transform", "translateY(475px)");
        }
    });

    $(".footer-nav-item").click(function (e) {
        var idName = $(this).attr("id").split("-")[0];
        console.log(idName)
        if(idName=="sectionInputPhone") {
            $("html,body").animate({
                scrollTop: 0
            });
            return false;
        }
        else {
            var _top = $("#" + idName).offset().top - 140;
            $("html,body").animate({
                scrollTop: _top
            });
            return false;
        }
    });

    //报价人数
    var array = [5, 8, 3, 2, 1, 2, 8, 25, 55, 59, 78, 64, 63, 55, 73, 93, 78, 71, 54, 51, 49, 40, 21, 7];
    var hours = new Date().getHours();
    var totalNumber = 0;
    for (var i = 0; i <= hours; i++) {
        totalNumber = array[i] + totalNumber;
    }
    $('.curr-number').html(totalNumber);
    var swiper = new Swiper('.swiper-container', {
        autoplay: true, //可选选项，自动滑动
        spaceBetween: 30,
        slidesPerView: 3,
        loop: true,
        pagination: {
            el: '.swiper-pagination',
        },
    });
    $('input').focus(function () {
        $(this).next(".errorTip").hide();
        $(this).next(".errorTip").next(".privacy").show();
    })

    $(".banner-button").click(function () {
        $(".offer-content").animate({
            width: "960px",
            opacity: "1"
        })
        $(".offer-box").fadeIn();
    })
    $(".close").click(function () {
        $(this).parent().find(".errorTip").hide();
        $(this).parent().find("input").css("border-color", "#ddd")
        $(".success-content").animate({
            width: "180px",
            opacity: " 0"
        })
        $(".submit-success").fadeOut();

    })
    $(".closeMask").click(function () {
        $(this).parent().find(".errorTip").hide();
        $(this).parent().find("input").css("border-color", "#ddd")
        $(".offer-content").animate({
            width: "480px",
            opacity: " 0"
        })
        $(".offer-box").fadeOut();
    })
    //    间距
    $(".explain").mouseenter(function () {
        $(".distance-txt").fadeIn();
    })
    $(".explain").mouseleave(function () {
        $(".distance-txt").fadeOut();
    })
    //底部计算器
    var quotationFlag = false;
    $('.mask').click(function () {
        quotationFlag=false;
        $('.icon-arrow').css({
            transform: ' rotateX(180deg)'
        })
        $('.quotation-box').css({
            'transform': ' translate3d(0,475px,0)',
            'transition': 'all 0.4s ease-in-out'
        })
        $(this).hide();
    })
    //蒙版
    
    $('.quotation-header').click(function (event) {
        if (quotationFlag) {
            quotationFlag=false;
            $('.icon-arrow').css({
                transform: ' rotateX(180deg)',
                
            })
            $('.quotation-box').css({
                'transform': ' translate3d(0,475px,0)',
                'transition': 'all 0.4s ease-in-out'
            })
        } else {
            quotationFlag=true;
            $(".mask").show();
            $('.icon-arrow').css({
                transform: ' rotateX(0deg)'
            })
            $('.quotation-box').css({
                'transform': ' translate3d(0,0,0)',
                'transition': 'all 0.4s ease-in-out'
            })
        }
    })


    /** 报价弹窗 */
    var QuotationPopup =  $('#QuotationPopup');
    QuotationPopup.find('.mobile').on('input', function () {
        $('.mobileError').hide();
    });
    //鼠标滑过效果
    QuotationPopup.find(".mouseHover").mouseover(function () {
        QuotationPopup.find('.citySelect').css('color', '#212022');
    }).mouseleave(function () {
        QuotationPopup.find('.citySelect').css('color', '#83848e');
    });


    // 8秒后弹出报价弹窗
    setTimeout(function () {
        $('#QuotationPopup').fadeIn(300);
    },8000)
});
// 选择屏幕
var screenType = 0;
// 0为室内1为室外
$(".select-screen").change(function (e) {
    screenType = e.currentTarget.selectedIndex;
    if (e.currentTarget.selectedIndex == 0) {
        $('.indoor').show();
        $('.outdoor').hide();
    } else {
        $('.indoor').hide();
        $('.outdoor').show();
    }

})
// 电话号码
$('input#phone').focus(function () {
    $(this).next(".errorTip").hide();
});
// 电话号码
$('.value-div-half').focus(function () {
    $(this).css("border-color","#ddd");
    $(".size-error").hide();
});
$('input#phone').blur(function () {
    var phoneNum = $(this).val();
    if (phoneNum.length == 0) {
        $(this).css("border-color", "#f00")
        $(this).next(".errorTip").html('手机号码不能为空');
        $(this).next(".errorTip").show();
        return;
    } else if (!(/^1[3|4|5|8|9][0-9]\d{8}$/.test(phoneNum))) {
        $(this).css("border-color", "#f00")
        $(this).next(".errorTip").html('请输入正确的手机号码');
        $(this).next(".errorTip").show();
        return;
    }
    $(this).css("border-color", "#ddd");
})



var isClick = true;

function submit(obj, idx) {

    var mobile, city, prov, sem, cate = 1;
    // 百度事件统计
    trackBaidu(1);

    $(obj).parent().find(".errorTip").hide();
    $(obj).parent().find("input").css("border-color", "#ddd");
    mobile = $(obj).parent().find("input#phone").val();
    if(idx ==4){
        mobile = $('#QuotationPopup .mobile').val().trim();
    }
    if (mobile.length == 0) {
        $(obj).parent().find("input#phone").css("border-color", "#f00");
        $(obj).parent().find("input#phone").next(".errorTip").html('手机号不能为空').show().next(".privacy").hide();
        if(idx ==4){
            $('#QuotationPopup .mobileError').text('手机号不能为空').show();
        }
        return;
    } else if (!(/^1[3|4|5|8|9][0-9]\d{8}$/.test(mobile))) {
        $(obj).parent().find("input#phone").css("border-color", "#f00");
        $(obj).parent().find("input#phone").next(".errorTip").html('请输入正确的手机号码').show().next(".privacy").hide();
        if(idx ==4){
            $('#QuotationPopup .mobileError').text('请输入正确的手机号码').show();
        }
        return;
    }

    // 发接口
    city = globalData.selPos.city;
    prov = globalData.cityToProvince[city];
    sem = globalData.sem;
    var inquiryInfo = {
        cate: cate,
        mobile: mobile,
        city: city,
        sem: sem,
        prov: prov
    };
    $.each(inquiryInfo, function (key, value) {
        if (!value) {
            delete inquiryInfo[key];
        }
    });
    // 百度事件统计
    trackBaidu(2);

    if(!isClick){
        return;
    }else{
        isClick = false;
    }
    postDraft(inquiryInfo, {
        succ: function succ() {
            // 百度事件统计
            trackBaidu(3,idx);
            isClick = true;
            // 成功的样式
            $(".offer-content").animate({
                width: "480px",
                opacity: " 0"
            });
            $(".offer-box").fadeOut();
            $(".success-content").animate({
                width: "360px",
                opacity: " 1"
            });
            $(".submit-success").fadeIn();
            $(obj).parent().find("input#name").html("");
            $(obj).parent().find("input#phone").html("");

            if(idx == 4){
                $('#QuotationPopup').hide();
            }

        },fail:function(error){
            isClick = true;
            var msg = error.msg || "提交失败，请重试";
            alert(msg)
        }
    });
}


// 底部报价计算
function submitAndCount(obj) {
    var mobile, city, prov, sem, cate = 1;
    // 百度事件统计
    trackBaidu(1);

    $(obj).parent().find(".errorTip").hide();
    $(obj).parent().find("input").css("border-color", "#ddd");
    var mobile = $(obj).parent().find("input#phone").val();
    if (mobile.length == 0) {
        $(obj).parent().find("input#phone").css("border-color", "#f00");
        $(obj).parent().find("input#phone").next(".errorTip").next(".privacy").hide();
        $(obj).parent().find("input#phone").next(".errorTip").show();
        return;
    } else if (!(/^1[3|4|5|8|9][0-9]\d{8}$/.test(mobile))) {
        $(obj).parent().find("input#phone").css("border-color", "#f00")
        $(obj).parent().find("input#phone").next(".errorTip").next(".privacy").hide();
        $(obj).parent().find("input#phone").next(".errorTip").html('请输入正确的手机号码');
        $(obj).parent().find("input#phone").next(".errorTip").show();
        return;
    }
    // 手机号码正确就先发接口，宽高随后再校验
    city = globalData.selPos.city;
    prov = globalData.cityToProvince[city];
    sem = globalData.sem;
    var inquiryInfo = {
        cate: cate,
        mobile: mobile,
        city: city,
        sem: sem,
        prov: prov
    };
    $.each(inquiryInfo, function (key, value) {
        if (!value) {
            delete inquiryInfo[key];
        }
    });
    // 百度事件统计
    trackBaidu(2);

    if(!isClick){
        return;
    }else{
        isClick = false;
    }
    postDraft(inquiryInfo, {
        succ: function succ() {
            // 百度事件统计
            trackBaidu(3,3);
            isClick = true;

        },fail:function(){
            isClick = true;
        }
    });


    // 校验宽高
    var width = $('.width-val').val().trim();
    var height = $('.height-val').val().trim();
    if(!width){
        $('.width-val').css("border-color","#f00");
        $('.size-error').html('宽度不能为空或0').show();
        return
    }
    if(!height){
        $('.height-val').css("border-color","#f00");
        $('.size-error').html('高度不能为空或0').show();
        return
    }

    // 报价计算
    var priceIndex = 0;
    var priceNumber = 0;
    var priceDom = "";
    if (screenType == 0) {
        priceIndex = $(".indoor")[0].selectedIndex;
        priceDom = $(".indoor").children()[priceIndex];
    } else {
        priceIndex = $(".outdoor")[0].selectedIndex;
        priceDom = $(".outdoor").children()[priceIndex];
    }
    priceNumber = $(priceDom).attr("data-price");
    var sum = parseInt(width) * parseInt(height) * parseInt(priceNumber);
    $(".priceNum").html(sum);

}
// 城市选择
(function () {
    var cityList = [{ "letter": "A", "list": ["阿拉善盟", "鞍山市", "安庆市", "安阳市", "阿坝藏族羌族自治州", "安顺市", "阿里地区", "安康市", "阿克苏地区", "阿勒泰地区", "阿拉尔市", "澳门特别行政区"] }, { "letter": "B", "list": ["北京市", "保定市", "包头市", "巴彦淖尔市", "本溪市", "白山市", "白城市", "蚌埠市", "亳州市", "滨州市", "北海市", "百色市", "白沙黎族自治县", "保亭黎族苗族自治县", "巴中市", "毕节市", "保山市", "宝鸡市", "白银市", "博尔塔拉蒙古自治州", "巴音郭楞蒙古自治州", "北屯市"] }, { "letter": "C", "list": ["承德市", "沧州市", "长治市", "赤峰市", "长春市", "常州市", "滁州市", "池州市", "长沙市", "常德市", "郴州市", "潮州市", "崇左市", "澄迈县", "昌江黎族自治县", "成都市", "楚雄彝族自治州", "昌都市", "昌吉回族自治州"] }, { "letter": "D", "list": ["大同市", "大连市", "丹东市", "大庆市", "大兴安岭地区", "东营市", "德州市", "东莞市", "儋州市", "东方市", "定安县", "德阳市", "达州市", "大理白族自治州", "德宏傣族景颇族自治州", "迪庆藏族自治州", "定西市"] }, { "letter": "E", "list": ["鄂尔多斯市", "鄂州市", "恩施土家族苗族自治州"] }, { "letter": "F", "list": ["抚顺市", "阜新市", "阜阳市", "福州市", "莆田市", "抚州市", "佛山市", "防城港市"] }, { "letter": "G", "list": ["赣州市", "广州市", "桂林市", "贵港市", "广元市", "广安市", "甘孜藏族自治州", "贵阳市", "甘南藏族自治州", "果洛藏族自治州", "固原市"] }, { "letter": "H", "list": ["邯郸市", "衡水市", "呼和浩特市", "呼伦贝尔市", "葫芦岛市", "哈尔滨市", "鹤岗市", "黑河市", "淮安市", "杭州市", "湖州市", "合肥市", "淮南市", "淮北市", "黄山市", "菏泽市", "鹤壁市", "黄石市", "黄冈市", "衡阳市", "怀化市", "惠州市", "河源市", "贺州市", "河池市", "海口市", "红河哈尼族彝族自治州", "汉中市", "海东市", "海北藏族自治州", "黄南藏族自治州", "海南藏族自治州", "海西蒙古族藏族自治州", "哈密市", "和田地区"] }, { "letter": "J", "list": ["晋城市", "晋中市", "锦州市", "吉林市", "鸡西市", "佳木斯市", "嘉兴市", "金华市", "景德镇市", "九江市", "吉安市", "济南市", "济宁市", "焦作市", "济源市", "荆门市", "荆州市", "江门市", "揭阳市", "嘉峪关市", "金昌市", "酒泉市"] }, { "letter": "K", "list": ["开封市", "昆明市", "克拉玛依市", "克孜勒苏柯尔克孜自治州", "喀什地区", "可克达拉市", "昆玉市"] }, { "letter": "L", "list": ["廊坊市", "临汾市", "吕梁市", "辽阳市", "辽源市", "连云港市", "丽水市", "六安市", "龙岩市", "莱芜市", "临沂市", "聊城市", "洛阳市", "娄底市", "柳州市", "来宾市", "临高县", "乐东黎族自治县", "陵水黎族自治县", "泸州市", "乐山市", "凉山彝族自治州", "六盘水市", "丽江市", "临沧市", "拉萨市", "林芝市", "兰州市", "陇南市", "临夏回族自治州"] }, { "letter": "M", "list": ["牡丹江市", "马鞍山市", "茂名市", "梅州市", "绵阳市", "眉山市"] }, { "letter": "N", "list": ["南京市", "南通市", "宁波市", "南平市", "宁德市", "南昌市", "南阳市", "南宁市", "内江市", "南充市", "怒江傈僳族自治州", "那曲地区"] }, { "letter": "P", "list": ["盘锦市", "萍乡市", "平顶山市", "濮阳市", "攀枝花市", "普洱市", "平凉市"] }, { "letter": "Q", "list": ["秦皇岛市", "齐齐哈尔市", "七台河市", "衢州市", "泉州市", "青岛市", "潜江市", "清远市", "钦州市", "琼海市", "琼中黎族苗族自治县", "黔西南布依族苗族自治州", "黔东南苗族侗族自治州", "黔南布依族苗族自治州", "曲靖市", "庆阳市"] }, { "letter": "R", "list": ["日照市", "日喀则市"] }, { "letter": "S", "list": ["石家庄市", "朔州市", "沈阳市", "四平市", "松原市", "双鸭山市", "绥化市", "上海市", "苏州市", "宿迁市", "绍兴市", "宿州市", "厦门市", "三明市", "上饶市", "三门峡市", "商丘市", "十堰市", "随州市", "神农架林区", "邵阳市", "韶关市", "深圳市", "汕头市", "汕尾市", "三亚市", "三沙市", "遂宁市", "山南市", "商洛市", "石嘴山市", "石河子市", "双河市"] }, { "letter": "T", "list": ["天津市", "唐山市", "太原市", "通辽市", "铁岭市", "通化市", "泰州市", "台州市", "铜陵市", "泰安市", "漯河市", "天门市", "屯昌县", "铜仁市", "铜川市", "天水市", "吐鲁番市", "塔城地区", "图木舒克市", "铁门关市", "台湾省"] }, { "letter": "W", "list": ["乌海市", "乌兰察布市", "无锡市", "温州市", "芜湖市", "潍坊市", "威海市", "武汉市", "梧州市", "五指山市", "文昌市", "万宁市", "文山壮族苗族自治州", "渭南市", "武威市", "吴忠市", "乌鲁木齐市", "五家渠市"] }, { "letter": "X", "list": ["邢台市", "忻州市", "兴安盟", "锡林郭勒盟", "徐州市", "宣城市", "新余市", "新乡市", "许昌市", "信阳市", "襄阳市", "孝感市", "咸宁市", "仙桃市", "湘潭市", "湘西土家族苗族自治州", "西双版纳傣族自治州", "西安市", "咸阳市", "西宁市", "香港特别行政区"] }, { "letter": "Y", "list": ["阳泉市", "运城市", "营口市", "延边朝鲜族自治州", "伊春市", "盐城市", "扬州市", "鹰潭市", "宜春市", "烟台市", "宜昌市", "岳阳市", "益阳市", "永州市", "阳江市", "云浮市", "玉林市", "宜宾市", "雅安市", "玉溪市", "延安市", "榆林市", "玉树藏族自治州", "银川市", "伊犁哈萨克自治州"] }, { "letter": "Z", "list": ["张家口市", "朝阳市", "镇江市", "舟山市", "漳州市", "淄博市", "枣庄市", "郑州市", "周口市", "驻马店市", "株洲市", "张家界市", "珠海市", "湛江市", "肇庆市", "中山市", "重庆市", "自贡市", "资阳市", "遵义市", "昭通市", "张掖市", "中卫市"] }];
    var CityIndex = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"];
    var CityHots = ["北京市", "长春市", "常州市", "长沙市", "大连市", "贵阳市", "广州市", "哈尔滨市", "济南市", "昆明市", "宁波市", "青岛市", "上海市", "深圳市", "无锡市", "西安市", "厦门市", "郑州市"];
// 渲染热门城市
    var hotDom = '';
    $.each(CityHots, function (index, value) {
        hotDom += '<a data-city="' + value + '">' + value + '</a>';
    });
    $('#citySelector .HOT ').html('<dl class="hots selected"><dd>' + hotDom + '</dd></dl>');

    //渲染城市列表

    var ABCDE = '';
    var FGHIJ = '';
    var KLMNOP = '';
    var QRSTUV = '';
    var WXYZ = '';
    $.each(cityList, function (index, item) {
        var cityDom = '';
        var letter = '<dt>' + item.letter + '</dt>';
        var citys = '';
        $.each(item.list, function (i, city) {
            citys += '<a data-city="' + city + '">' + city + '</a>';
        });
        cityDom = letter + '<dd>' + citys + '</dd>';
        if ("ABCDE".indexOf(item.letter) > -1) {
            ABCDE += cityDom;
        }else if ("FGHIJ".indexOf(item.letter) > -1) {
            FGHIJ += cityDom;
        }else if("KLMNOP".indexOf(item.letter) > -1) {
            KLMNOP += cityDom;
        }else if("QRSTUV".indexOf(item.letter) > -1) {
            QRSTUV += cityDom;
        }else if("WXYZ".indexOf(item.letter) > -1) {
            WXYZ += cityDom;
        }
    });
    $('#citySelector .ABCDE ').html('<dl class="selected">' + ABCDE + '</dl>');
    $('#citySelector .FGHIJ ').html('<dl class="selected">' + FGHIJ + '</dl>');
    $('#citySelector .KLMNOP ').html('<dl class="selected">' + KLMNOP + '</dl>');
    $('#citySelector .QRSTUV ').html('<dl class="selected">' + QRSTUV + '</dl>');
    $('#citySelector .WXYZ ').html('<dl class="selected">' + WXYZ + '</dl>');

})();
//切换城市选择
function changeCard(e,obj){
    var card = $(e.target).attr('card');
    var EleShow = '.HOT';
    $(obj).parent().find('a').removeClass('selected')
    $(e.target).addClass('selected')
    switch(card){
        case '1':
            EleShow = '.ABCDE';
            break;
        case '2':
            EleShow = '.FGHIJ';
            break;
        case '3':
            EleShow = '.KLMNOP';
            break;
        case '4':
            EleShow = '.QRSTUV';
            break;
        case '5':
            EleShow = '.WXYZ';
            break;
    }
    $('#citySelector .list').hide();
    $(EleShow).show();
}
//选择城市
function changeCity(e,obj){
    var selCity = e.target.innerHTML;
    globalData.selPos.city = selCity;
    globalData.selPos.prov = globalData.cityToProvince[selCity];
    $('.citySelect').html(selCity);
    $('.CityPanel').hide();
}
//打开城市选择
function openCitySelect(){
    $('.CityPanel').show();
}
//关闭弹窗
function closePanel(e,obj){
    if(e.target === obj){
        $(obj).hide();
    }
}

// 展开收起下拉框
function openOptionsPop(target) {
    $('#QuotationPopup .options').hide();
    $(target).parent().find('.options').slideToggle(300);
    $(target).find('.icon-circle-down2').toggleClass('rotate');
}
function chooseOptionInstall(e,target) {
    var that = this;
    var obj = e.target;
    if (target === obj) {
        $(target).slideToggle(300);
        $(obj).parents('.com-input').find('.icon-circle-down2').toggleClass('rotate');
    } else {
        var val = obj.innerHTML;
        var type = $(obj).attr('type');
        var colorHtml = '';
        var colorval = '';
        var colortype = '';
        var locationHtml = '';
        var locationval = '';
        var locationtype = '';
        var distance = 0;
        var width,height;
        $(target).slideToggle(300);
        $(obj).parents('.com-input').find('.icon-circle-down2').toggleClass('rotate');
        $(obj).parents('.com-input').find('.select-val').html(val);
        switch (type) {
            case '3'://门头屏
                distance = 10;
                colorval = '单色';
                colortype = 1;
                colorHtml = '<i class="item" type="1">单色</i><i class="item" type="2">双色</i>';
                locationval = '半户外';
                locationtype = 3;
                locationHtml = '<i class="item" type="1">户外</i><i class="item" type="3">半户外</i>';
                width = 3;
                height = 0.5;
                break;
            case '2'://商业广告屏
                distance = 6;
                colorval = '全彩';
                colortype = 3;
                colorHtml = '<i class="item" type="1">单色</i><i class="item" type="2">双色</i><i class="item" type="3">全彩</i>';
                locationval = '户外';
                locationtype = 1;
                locationHtml = '<i class="item" type="1">户外</i><i class="item" type="2">室内</i>';
                width = 8;
                height = 4.5;
                break;
            case '5'://室内高清屏
                distance = 4;
                colorval = '全彩';
                colortype = 3;
                colorHtml = '<i class="item" type="1">单色</i><i class="item" type="2">双色</i><i class="item" type="3">全彩</i>';
                locationval = '室内';
                locationtype = 2;
                locationHtml = '<i class="item" type="1">户外</i><i class="item" type="2">室内</i>';
                width = 6;
                height = 4;
                break;
            case '4'://交通诱导屏
                distance = 10;
                colorval = '全彩';
                colortype = 3;
                colorHtml = '<i class="item" type="1">单色</i><i class="item" type="2">双色</i><i class="item" type="3">全彩</i>';
                locationval = '户外';
                locationtype = 1;
                locationHtml = '<i class="item" type="1">户外</i>';
                width = 3;
                height = 0.5;
                break;
            case '1'://安防监控屏
                distance = 2.5;
                colorval = '全彩';
                colortype = 3;
                colorHtml = '<i class="item" type="3">全彩</i>';
                locationval = '室内';
                locationtype = 2;
                locationHtml = '<i class="item" type="1">户外</i><i class="item" type="2">室内</i>';
                width = 5;
                height = 3;
                break;
            default:
                distance = 6;
                colorval = '全彩';
                colortype = 3;
                colorHtml = '<i class="item" type="3">全彩</i>';
                locationval = '户外';
                locationtype = 1;
                locationHtml = '<i class="item" type="1">户外</i><i class="item" type="2">室内</i>';
                width = 8;
                height = 4.5;
                break
        }
        var QuotationPopup = $('#QuotationPopup ');
        QuotationPopup.find('.install .select').attr('type', type);
        QuotationPopup.find('.color .options').html(colorHtml);
        QuotationPopup.find('.color .select-val').html(colorval);
        QuotationPopup.find('.color .select').attr('type', colortype);
        QuotationPopup.find('.location .options').html(locationHtml);
        QuotationPopup.find('.location .select-val').html(locationval);
        QuotationPopup.find('.location .select').attr('type', locationtype);
        QuotationPopup.find('.distance .input').val(distance);
        QuotationPopup.find('.width').val(width);
        QuotationPopup.find('.height').val(height);
    }
}

function chooseOptionPop(e,target) {
    if (target === e.target) {
        $(target).slideToggle(300);
        $(e.target).parents('.com-input').find('.icon-circle-down2').toggleClass('rotate');
    } else {
        $(target).slideToggle(300);
        $(e.target).parents('.com-input').find('.icon-circle-down2').toggleClass('rotate');
        var val = e.target.innerHTML;
        $(e.target).parents('.com-input').find('.select-val').html(val);
    }
}



/** ===== 会话动画模块 ===== */
(function(){
    var myDate = new Date();
    var currGroup = 9;//当前已经使用的问答组的index
    var changeRate = 5; //随机变化的参数
    var data = [["洲明这个牌子怎么样？","洲明小间距品质很不错的"],["南昌西湖区能来装吗？","能，我就在西湖区，1小时内上门"],["想在饭店里装块大屏","饭店多大面积呢？"],["我想安个8平米的广告屏","是户外全彩的吗？"],["想安P4户外全彩的屏","具体尺寸是多少？"],["公路边上的高架屏能装吗？","可以的"],["价格怎么算呢？","设备材料费和路费"],["明天你能过来安装吗？","可以，我们同城"],["广州led屏幕p6多少钱？","你想多大面积的屏幕"],["p4是什么意思？","是间距，数字越小，画面越清晰"],["p4和p6显示区别大吗？","p4更清晰，p6户外使用"],["您这价格能再便宜些吗？","已经免安装费了，亲"],["送货上门吗？有安装费吗？","送货上门，安装免费"],["你家怎么比别人贵？","蓝普是大品牌，质量过硬"],["支持跨省安装吗？","支持，我们全国业务都能做"],["小镇上装门头屏能上门吗？","可以寄货到家，自己安装更划算哦"],["led屏一平方多少钱？","对颜色间距品牌有什么要求"],["p3led全彩显示屏价格","小间距的会稍微贵一点"],["p4led全彩显示屏怎么卖","不同品牌价格也不同"],["p5led全彩屏多钱？","您一次要买多少平米？"],["p10户外全彩显示屏多少钱？","1200一平安装"],["led电子屏什么牌子好","你的屏幕是用来做什么的？"],["led显示屏有哪些品牌","很多，要看屏幕具体需求"],["led显示屏厂家有哪些","厂家对起买量是有限制的"],["我要防水的户外显示屏","户外led屏都防水的"],["自己安装？我不会呀！","我们会远程指导您安装"],["小间距弧形的，能做吗？","弧形是需要定制的"],["小间距有什么好处？","间距越小，清晰度越高"],["找你安装，质保多久？","行业内都是质保1年的"],["洲明led小间距，怎么卖？","您具体要哪种间距？"],["户外全彩屏，播广告用","那P8的就可以了"],["室内会议室的led屏","建议您安装P3或P4的"],["明天可以上门安装吗","您备品齐全，我随时可上门"],["找北京led屏供应商","具体安装在北京哪里？"],["面积大概12平米","是户外显示广告用吗"],["主要用来播广告","建议选择户外全彩P8屏"],["led屏里面带音响吗？","可以带音响"],["想问下户外广告屏多少钱？","要什么规格的"],["能做P3的全彩led屏吗","可以，我们专业做P3的"],["你有洲明的小间距led屏吗？","有的，你要哪个间距"],["蓝普这个牌子怎么样","蓝谱性价比很高"],["强力质量怎么样","强力户外屏不错"],["户外用哪个间距比较好？","P6或者P8都可以"],["室内用p3可以吗？","您的观看距离有多远"],["全彩p5怎么收费？","不同品牌价格也不同的"],["您报价多少 ？","3500全包"],["上门费用怎么收？","按照距离远近计算"],["2平米的门头，大概多少钱？","大概2000块以内"],["配电柜需要自己提供吗？","我们可以提供的"],["好几家的报价都比你低"," 亲，是同样的配置吗？"],["你们是led屏厂家吗？","我们的货源是厂家直供的"],["什么时候提供具体的报价？","具体报价我电话跟您说"],["质保多久？","质保您2年，没问题"],["你们提供配件吗？","如果需要，是可以提供的"],["点间距是什么？","灯珠距离，间距越小越清晰"],["比较急，今天能上门吗？","可以的，我就在浉河区"],["您好，在吗?","在，屏幕要求已在详情里说明了"],["可以邮寄过来吗？","可以，可包邮"],["为什么需要钢结构？","是用来固定用的"],["能提供发票吗？","可以邮寄发票给您"],["led大屏幕多少钱？","这要看具体的规格要求"],["配置都差不多","给您做广告屏，我们用蓝普的屏"],["以后修改文字能帮我改吗？","必须可以呀，上门改都没问题"],["不着急，我就是先问问","没关系，您还有哪些想要了解的"],["人工费怎么算？","一天一人300块"],["大概需要几天安完？","这个比较复杂，需要3天左右"],["工期大概多久？","你这个项目有些复杂"],["支持播放外国语言吗？","我们支持十六国语言显示"],["可以连接WiFi吗","可以的，里面有WiFi模块"],["你们售后是怎样的？","我们质保您1年"],["那把合同给我吧","好的，明天之前发您"],["什么时候可以上门来看一下","今天下午就可以"],["可以监控屏幕播放的内容吗？","需要额外接摄像头"],["散热设备谁提供？","如果需要，我们可以提供"],["高速公路旁边的那种，能做吗？","可以的，最好有场地照片"],["深圳市南山区","您想安在哪里？"],["平桥区万象城","您的广告屏在哪里使用"],["户外广告屏","您好，需要什么屏？"],["你好，在北京海淀区","你好，什么规格？安装在哪？"],["大概2平米","专业做门头，你要多大面积"],["p4安在会议室","什么规格，安装在哪？"],["好的，谢谢","在吗？电话联系给你报价"],["是的，美尚百货的楼体上","是装在楼体上的吗？"],["是的，在马路边上","你这是要装个高炮类型的？"],["6月8号就要用了","什么时候使用？"],["全彩的价格怎么样呢？","门头屏用全彩的更醒目哦！"],["那您给装p几的呢？","才5㎡，做全彩也就2000"],["我跟隔壁店一起装能再优惠不","p10的就可以了，比较实惠！"],["好的，谢谢","有什么问题随时联系我"],["不会安装","门头屏您可以自己安装，更便宜"],["p5的","你的屏幕间距是多大？"],["太麻烦了，还是你们上门装吧","邮寄给您自己装，有视频教程"],["那太好了，感谢","我也在经开区，安装费就不收您了"],["嗯，已经发你图片了","有图片更好报价"],["大概15米宽、8米高","您装个多大的，长宽多少？"],["上海市静安区","屏幕在什么位置？"],["就是啊，所以才换成led屏","咱这冬天雾霾重，得装个亮度高的"],["可是价格还是有点贵","强力也是大牌子，不容易坏"],["做广告屏我不能只图便宜","洲明虽然质量好，但是价格也贵呀"],["10米多的样子","您的屏幕需要架多高？"],["需要","散热设备需要我们提供吗？"],["浦东张江","你在上海哪儿？"],["好的","广州地区，可以上门"],["上门费怎么计算？","您好，上门费另算的"],["清晰一点","您对清晰度有什么要求？"],["那我选择p8吧","p8比P10要更清晰一些"],["不需要，户外信息屏那种","需要高空安装吗？"],["3×5米的样子","大概需要多少平米？"],["质量要好，价格好商量","你对品牌有要求吗？"],["室内，会议室用的","室内还是室外的屏幕？"],["2米吧","最佳视距有多远？"],["播放广告视频","led屏是用来干什么的？"],["哪有什么可以替换吗","你的这个模组已经停产了"],["价格怎么样","洲明是高端品牌，质量好"],["它有小间距的屏吗","蓝普性价比很高的"],["全彩，也要播图片的","全彩还是双色？"],["后天上午可以吗","什么时候方便，我们上门安装"],["10万以内","有大概的预算吗？"],["有质保吗？","一平米大概1200元左右"],["最好可以上门帮调试","我们可以上门帮忙安装"],["我在朝阳区","本市30分钟就可以上门"],["主要是图片和文字","屏幕用来播放什么？"],["那长沙可以上门吗","我们全国都有网点的"],["您打我电话就行","上门安装led屏，欢迎联系"],["有p25的吗？","专业制作小间距"],["是的，能做吗？","你是要做弧形屏是吗？"],["需要，在室外","需要防水吗？"],["不好意思，刚刚没听到","怎么打你电话打不通啊？"],["你们报价多少？","你这个预算，太低了"],["都是什么价格呢？","餐厅内使用，用p4或p5比较好！"],["是的，承重墙","led屏挂的墙是实心墙吗？"],["好的，我知道了","你这个需要额外的钢结构"],["那就p3吧","P3比P4更清晰，价格差不多"],["价格贵吗？","现在户外都用P8了"],["4×6米的户外屏","屏幕尺寸多大？"],["8万，不能再多了","您的预算大概是多少？"],["对，25层的外面","屏幕是安在大楼外面吗？"],["室内两块屏，室外一块屏","您一共要安几块屏？"],["医院里面展示信息的","室内屏是用来做什么的？"],["有人，昨天来的","您好，屏幕有人去安装吗"],["通过平台联系我","我怎么联系您？"],["宝安区海雅缤纷城","具体安屏位置是哪里？"],["不能再便宜了吗？","最低报价12万"],["什么时候可以上门？","这个价格我可以做"],["没有，你有推荐吗？","你有指定的品牌吗？"],["p8多少钱？","p10单色没货了，p8可以吗？"],["p10怎么卖","p12以上的已经停产，p10最实惠！"],["30平米的样子","安装屏幕的房间有多大？"],["费电吗？","户外led屏颜色都比较亮"],["全彩多少钱一平？","门头屏现在用全彩效果更好"]];

    changeOnlineNum();
    initBoxes();

    function initBoxes() {
        currGroup = 25;
        changeRate = 5;

        // 取前n条插入dom
        var tpl = '';
        for (var i = 0; i < currGroup; i++) {
            tpl += '<div class="box lg-5 md-4 sm-3"><div class="box-y"><p class="text">' + data[i][0] + '</p><span class="icon-use"></span></div><div class="box-b"><span class="icon-supplier"></span><p class="text">' + data[i][1] + '</p></div></div>'
        }
        $('#chating').find('.tpl').html(tpl);
        randomBox();
        boxNum = currGroup;
    }
    // 重复随机选取多个方块，执行变化方法
    function randomBox() {
        setInterval(function () {
            var i = 0;
            do {
                var random = parseInt(Math.random() * changeRate);
                if (2 * i + random > boxNum) {
                    return
                }
                var box = $('#chating').find('.box').eq(2 * i + random);
                changeStatus(box);
                i += random;
            } while (i < boxNum);
        }, 3000);
    }
    // 单个方块的变化
    function changeStatus(jqDom) {
        // 累加要取得的词条索引值  (-3是因为循环调用此方法会出现currGroup的值溢出的情况导致报错，无奈只好如此)
        if (currGroup >= data.length - 6) {
            currGroup = 0;
            return
        } else {
            currGroup++;
        }
        // 生成随机结果备用
        var flag1, flag2, flag3, flag4, flag5, random1 = Math.random(), random2 = Math.random();
        var left, right, top, bottom;
        if (random2 > 0.5) {
            flag2 = 'right';
            flag3 = 'left';
        } else {
            flag2 = 'left';
            flag3 = 'right';
        }
        if (Math.round(random2 * 10) % 2 == 0) {
            flag4 = 'top';
            flag5 = 'bottom';
        } else {
            flag4 = 'bottom';
            flag5 = 'top';
        }
        //设置每一个动画的随机延迟时间
        var randomDelay = parseInt(random1 * 1000);
        // 判断当前状态，针对性改变
        var b = jqDom.find('.box-b');
        var y = jqDom.find('.box-y');
        if (!data[currGroup]) {
            return
        }
        var text_b = data[currGroup][1];
        var text_y = data[currGroup][0];
        var textb = b.find('.text');
        var texty = y.find('.text');
        if (b.css('height') == '0px') {
            //蓝色显示
            b.delay(randomDelay).css('height', '100%');
            textb.text(text_b).delay(300).css('width', '62%');
            // 黄色块
            y.delay(randomDelay).find('.text').css('width', '0px').text(text_y);
        } else if (b.css('width') == '0px') {
            //蓝色显示
            b.delay(randomDelay).css('width', '100%');
            textb.text(text_b).delay(300).css('width', '62%');
            // 黄色块
            y.delay(randomDelay).find('.text').css('width', '0px').text(text_y);
        } else {
            /** 随机改变色块的动画方向 */
            random1 > 0.5 ? flag1 = 'height' : flag1 = 'width';
            b.delay(randomDelay).css(flag1, '0px').delay(800).find('.text').css('width', '0px');
            y.delay(randomDelay).find('.text').text(text_y).delay(300).css('width', '62%');
            setTimeout(function () {
                jqDom.find('.box-b').css({ flag2: 'auto', flag3: '0', flag4: 'auto', flag5: '0' });
                textb.text(text_b);
            }, 1000);
        }
    }
    function changeOnlineNum() {
        var customerNum=2500;
        var coefficient=3.73;
        myDate = new Date();
        var hours = myDate.getHours();
        var num1,num2;
        if (hours >= 24 || hours < 1) {
            num1 = Math.round(customerNum*0.02);
            num2 = Math.round(Math.round(customerNum*0.02)*3.73);
        }else if (hours >= 1 && hours < 2) {
            num1 = Math.round(customerNum*0.012);
            num2 = Math.round(Math.round(customerNum*0.012)*3.73);
        }else if (hours >= 2 && hours < 3) {
            num1 = Math.round(customerNum*0.01);
            num2 = Math.round(Math.round(customerNum*0.01)*3.73);
        }else if (hours >= 3 && hours < 4) {
            num1 = Math.round(customerNum*0.013);
            num2 = Math.round(Math.round(customerNum*0.013)*3.73);
        }else if (hours >= 4 && hours < 5) {
            num1 = Math.round(customerNum*0.015);
            num2 = Math.round(Math.round(customerNum*0.015)*3.73);
        }else if (hours >= 5 && hours < 6) {
            num1 = Math.round(customerNum*0.02);
            num2 = Math.round(Math.round(customerNum*0.02)*3.73);
        }else if (hours >= 6 && hours < 7) {
            num1 = Math.round(customerNum*0.015);
            num2 = Math.round(Math.round(customerNum*0.015)*3.73);
        }else if (hours >= 7 && hours < 8) {
            num1 = Math.round(customerNum*0.02);
            num2 = Math.round(Math.round(customerNum*0.02)*3.73);
        }else if (hours >= 8 && hours < 9) {
            num1 = Math.round(customerNum*0.023);
            num2 = Math.round(Math.round(customerNum*0.023)*3.73);
        }else if (hours >= 9 && hours < 10) {
            num1 = Math.round(customerNum*0.021);
            num2 = Math.round(Math.round(customerNum*0.021)*3.73);
        }else if (hours >= 10 && hours < 11) {
            num1 = Math.round(customerNum*0.032);
            num2 = Math.round(Math.round(customerNum*0.032)*3.73);
        }else if (hours >= 11 && hours < 12) {
            num1 = Math.round(customerNum*0.022);
            num2 = Math.round(Math.round(customerNum*0.022)*3.73);
        }else if (hours >= 12 && hours < 13) {
            num1 = Math.round(customerNum*0.019);
            num2 = Math.round(Math.round(customerNum*0.019)*3.73);
        }else if (hours >= 13 && hours < 14) {
            num1 = Math.round(customerNum*0.029);
            num2 = Math.round(Math.round(customerNum*0.029)*3.73);
        }else if (hours >= 14 && hours < 15) {
            num1 = Math.round(customerNum*0.014);
            num2 = Math.round(Math.round(customerNum*0.014)*3.73);
        }else if (hours >= 15 && hours < 16) {
            num1 = Math.round(customerNum*0.013);
            num2 = Math.round(Math.round(customerNum*0.013)*3.73);
        }else if (hours >= 16 && hours < 17) {
            num1 = Math.round(customerNum*0.025);
            num2 = Math.round(Math.round(customerNum*0.025)*3.73);
        }else if (hours >= 17 && hours < 18) {
            num1 = Math.round(customerNum*0.018);
            num2 = Math.round(Math.round(customerNum*0.018)*3.73);
        }else if (hours >= 18 && hours < 19) {
            num1 = Math.round(customerNum*0.019);
            num2 = Math.round(Math.round(customerNum*0.019)*3.73);
        }else if (hours >= 19 && hours < 20) {
            num1 = Math.round(customerNum*0.026);
            num2 = Math.round(Math.round(customerNum*0.026)*3.73);
        }else if (hours >= 20 && hours < 21) {
            num1 = Math.round(customerNum*0.03);
            num2 = Math.round(Math.round(customerNum*0.03)*3.73);
        }else if (hours >= 21 && hours < 22) {
            num1 = Math.round(customerNum*0.02);
            num2 = Math.round(Math.round(customerNum*0.02)*3.73);
        }else if (hours >= 22 && hours < 23) {
            num1 = Math.round(customerNum*0.02);
            num2 = Math.round(Math.round(customerNum*0.02)*3.73);
        }else if (hours >= 23 && hours < 24) {
            num1 = Math.round(customerNum*0.01);
            num2 = Math.round(Math.round(customerNum*0.01)*3.73);
        }
        num1 += 1;
        num2 += 2;
        $('.customerOnline').text(num1);
        $('.engineerOnline').text(num2);
    }
})()



/** 百度统计事件
 * type: 1 ==  点击按钮就计算一次
 * type: 2 ==  手机号正确并点击按钮
 * type: 3 ==  手机号正确并提交草稿成功
 * */
function trackBaidu(type,pos) {
    var src = 'http://www.yongpingba.com/track/Click_Btn.html';

    if (type == 2) {
        src = 'http://www.yongpingba.com/track/Click_With_Mobile.html';
    } else if (type == 3) {
        if(pos == 3){
            src = 'http://www.yongpingba.com/track/Click_And_Submit_Bottom.html';
        }else if(pos == 2){
            src = 'http://www.yongpingba.com/track/Click_And_Submit_Main.html';
        }else if(pos == 4){
            src = 'http://www.yongpingba.com/track/Click_And_Submit_Modal.html';
        }else{
            src = 'http://www.yongpingba.com/track/Click_And_Submit_Banner.html';
        }
    }

    // 百度事件统计
    var iframe = '<div class="hide"><iframe src="' + src + '"></iframe>"</div>';

    $('body').append(iframe);
}

// 提交需求草稿
function postDraft(data, cb) {
    ajax_post("/Client/Demand/postDraft", data, cb);
}

/** ajax请求方法 */
function ajax_post(url, data, cb) {
    var URL = "https://opc.wanpinghui.com/api" + url;
    $.ajax(URL, $.extend({
        method: 'POST',
        data: data,
        dataType: "json",
        timeout: 30000,
        xhrFields: {
            withCredentials: true
        },
        headers: {
            'Accept': 'application/x-www-form-urlencoded',
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        contentType: 'application/x-www-form-urlencoded',
        success: function success(json, status, xhr) {
            cb && cb.always && cb.always(json);
            if (json.status == "200") {
                cb && cb.succ && cb.succ(json);
            } else {
                cb && cb.fail && cb.fail(json);
            }
        },
        error: function error(xhr, status, thrown) {
            console.log("[!err!](" + url + "): status: " + xhr.status + ", msg: " + thrown);
            cb && cb.fail && cb.fail();
            console.error("接口[" + url + "]：失败");
        }
    }));
}